package ArrayPackage2;

/**
 * @author Lzm
 * @version 1.0
 */
public class sortedSquares_ {

  public int[] sortedSquares(int[] nums) {
    int[] result = new int[nums.length];
    if (nums == null || nums.length == 0){
      return result;
    }
    int index = result.length - 1;
    int left = 0;
    int right = result.length - 1;
    while(left < right){
      if (nums[left] * nums[left] > nums[right] * nums[right]){
        result[index--] = nums[left] * nums[left];
        left++;
      }
      else{
        result[index--] = nums[right] * nums[right];
        right--;
      }
    }
    return result;
  }



}
